<?php

namespace App\Tcp;

class User extends Base
{

    /**
     * 重启服务清空tcp登录缓存
     */
    public static function cleanLoginCash()
    {
        $redis = self::redis();
        $redis -> del(self::TCP_LOGIN_KEY);
        $redis -> del(self::FD_UID_KEY);
    }

    /**
     * redis登录
     */
    public static function login($param, $fd)
    {
        if (!$uid = $param['uid'] ?? '') return self::errorJSON();
        $redis = self::redis();
        if ($redis -> hSet(self::TCP_LOGIN_KEY, $uid, $fd) && $redis->hSet(self::FD_UID_KEY, $fd, $uid)) return self::successJSON();
        return self::errorJSON();
    }

    /**
     * 加入群组
     */
    public static function addGroup($param, $fd)
    {
        if (!($uid = $param['uid'] ?? '') || !($groupId = $param['group_id'] ?? '')) return self::errorJSON();
        $redis = self::redis();
        var_dump(self::USER_GROUP_KEY.$groupId);
        if ($redis -> sAdd(self::USER_GROUP_KEY.'100', $uid)) return self::successJSON();
        return self::errorJSON();
    }

}